<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>登录</title>
		<link rel="stylesheet" type="text/css" href="../mobile/js/layer/css/layui.css"/>
		<link rel="stylesheet" type="text/css" href="css/main.css" />
	    <script src="../mobile/js/layer/layui.js"></script>
	    <script src="./js/jquery-1.9.1.js"></script>
	    <script src="./js/jquery-3.1.1.min.js"></script>
	    <script src="../mobile/js/jquery.cookie.js"></script>
	    <script src="./js/common.js"></script>
		<style>
			html,body{
				padding:0;
				margin:0;
				height:100%;
				width:100%;
			}
		</style>
		
	</head>
	
	<body>
		
		<div class="logininfo">
			<div class="loginbox">
				<form action="" method="get"  enctype='multipart/form-data'>
					<div class="loginmain">
						<table width="100%" cellspacing="0">
							<tr style="margin-bottom: 20px;">
								<td width="10%" >
									<i class="iconfont loginicon">&#xe654;</i>
								</td>
								<td width="90%">
									<input type="text" placeholder="请输入用户名" name="username" id="username" class="logininput" />
									<p class="prompt"></p>
								</td>
							</tr>
							
							<tr>
								<td width="10%" >
									<i class="iconfont loginicon" style="top: 15px;position: relative;">&#xe61c;</i>
								</td>
								<td width="90%">
									<input type="password" placeholder="请输入密码" name="password" id="password" class="logininput ma-to-30" />
								</td>
							</tr>
							
							<tr>
								<td colspan="2" align="center">
									<button type="button" onclick="getLogin()" class="loginbtn">登录</button>
								</td>
							</tr>
						</table>
					</div>
				</form>
			</div>
		</div>
		
	</body>
	

	
	<script>
	//首先验证是否登录
	$(function(){
	var geturl=url+ "/admin/adminapi/loginRequest";
	$.ajax({
			type: 'get',
			dataType: "json",
			url: geturl,
			success: function (dete) {
				// console.log(dete);
				if(dete == 3){
					//表示已经登录
					window.location.href="index.html";
				}

			},error:function(data){
				console.log("请检查您的网络");
			}
		});
	});


	var username=$.cookie("username");
	var psd=$.cookie("psd");

	$('#username').val(username);
	$('#password').val(psd);
	$('#username').mousemove(function () {
		$('#username').focus();
	});

	$('#password').mousemove(function () {
		$('#password').focus();
	});


	function getLogin(){

		var geturl=url+ "/admin/adminapi/adminlogin";
		
		var username = $('#username').val();

		var psd = $('#password').val();

		if(username==""){
			alert("请输入登录账号");
			$('#username').focus();
			return false;
		}else if(psd==""){
			alert("请输入登录密码");
			$('#username').focus();
			return false;
		}


		$.ajax({
			type: 'get',
			dataType: "json",
			url: geturl + '?nickname=' + username+"&password="+psd,
			success: function (data) {
				// console.log(data);
				//return false;
				// var suc=data.success;
				// var name=data.tooken;

				// if(suc.code == 4007){
				// 	alert(suc.message);
				// 	return false;
				// }else if(suc.code == 4012){
				// 	alert(suc.message);
				// 	return false;
				// }else if(suc.code == 4000){

				// 	//$.cookie('level', ''+ data.level +'',{expires: 3});
				// 	$.cookie('tooken', ''+ name +'',{expires: 3,path:'/'});
				// 	var tooken=$.cookie("tooken");

				// 	$.cookie('username', ''+ username +'',{expires: 3,path:'/'});
				// 	$.cookie('psd', ''+ psd +'',{expires: 3,path:'/'});
				if (data) {
					window.location.href="index.html";
				}




				// }

			},error:function(data){
				console.log("请检查您的网络");
			}
		});

	}

		
	</script>
	
</html>
